package com.ruicar.afs.cloud.batch.frame.bean;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import lombok.Getter;

import java.util.Calendar;
import java.util.Date;

/**
 * The type BatchDateInfo
 * <p>Description: </p>
 *
 * @author Fzero
 * @version 1.0
 * @date Created on 2020.08.06 12:31:51
 * @since 1.0
 */
public class BatchDateInfo {
    @Getter
    private final Date batchDate;
    @Getter
    private final boolean holiday;
    @Getter
    private final boolean weekEnd;
    @Getter
    private final boolean monthStart;
    @Getter
    private final boolean monthEnd;
    @Getter
    private final boolean sessionBegin;
    @Getter
    private final boolean sessionEnd;
    @Getter
    private final boolean yearStart;
    @Getter
    private final boolean halfYear;
    @Getter
    private final boolean yearEnd;
    public BatchDateInfo(Date batchDate,boolean holiday) {
        this.batchDate = batchDate;
        this.holiday = holiday;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(this.batchDate);
        calendar.set(Calendar.HOUR_OF_DAY,0);
        calendar.set(Calendar.MINUTE,0);
        calendar.set(Calendar.SECOND,0);
        calendar.set(Calendar.MILLISECOND,0);
        this.weekEnd = calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY;
        this.monthStart = calendar.get(Calendar.DAY_OF_MONTH)==1;
        this.monthEnd = this.getBatchStringDate().equalsIgnoreCase(DateUtil.format(DateUtil.endOfMonth(batchDate),DatePattern.PURE_DATE_PATTERN));
        this.sessionBegin = this.getBatchStringDate().equalsIgnoreCase(DateUtil.format(DateUtil.beginOfQuarter(batchDate),DatePattern.PURE_DATE_PATTERN));
        this.sessionEnd = this.getBatchStringDate().equalsIgnoreCase(DateUtil.format(DateUtil.endOfQuarter(batchDate),DatePattern.PURE_DATE_PATTERN));
        this.yearStart = this.getBatchStringDate().equalsIgnoreCase(DateUtil.format(DateUtil.beginOfYear(batchDate),DatePattern.PURE_DATE_PATTERN));
        Calendar tempCalendar = DateUtil.calendar(batchDate);
        tempCalendar.set(Calendar.MONTH,Calendar.JUNE);
        this.halfYear = this.getBatchStringDate().equalsIgnoreCase(DateUtil.format(DateUtil.endOfMonth(tempCalendar).getTime(),DatePattern.PURE_DATE_PATTERN));
        this.yearEnd = this.getBatchStringDate().equalsIgnoreCase(DateUtil.format(DateUtil.endOfYear(batchDate),DatePattern.PURE_DATE_PATTERN));
    }

    /**
     * Get batch string date string
     * 获取字符串批量日期 yyyyMMdd格式
     * @return the string
     */
    public String getBatchStringDate(){
        return DateUtil.format(this.batchDate, DatePattern.PURE_DATE_PATTERN);
    }
}
